package comqyf.nacoscloudzookeeper.listen;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class Listen {

    @Autowired
    private CuratorFramework client;

    public void listenPath(String node, PathChildrenCacheListener listener) throws Exception{
        PathChildrenCache pathChildrenCache = new PathChildrenCache(client, node, true);
        pathChildrenCache.getListenable().addListener(listener);
        pathChildrenCache.start();
    }
}
